﻿Imports System.Data
Imports System.Data.SqlClient

Public Class Autent3

    Dim password1 As String
    Dim numero As String


    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click

        Try
            Dim strCon As String = "Data Source=(local)\SQLEXPRESS ;Initial Catalog=cegan ;Integrated Security=True"
            Dim sql As String = "select pass from trabajador where rut_trabajador='" & textBox1.Text & "';"
            Dim tabla As New DataTable
            Dim adaptador As New SqlDataAdapter(sql, strCon)
            adaptador.Fill(tabla)

            password1 = tabla.Rows(0)("pass")


        Catch ex As Exception
            MsgBox("Usuario no registrado", MsgBoxStyle.Critical, "Error")
            GoTo salto
        End Try

        If textBox2.Text = password1 Then
            Try
                Dim strCon As String = "Data Source=(local)\SQLEXPRESS ;Initial Catalog=cegan ;Integrated Security=True"
                Dim sql As String = "update trabajador set pass='" & TextBox3.Text & "' where rut_trabajador='" & textBox1.Text & "';"
                Dim tabla As New DataTable
                Dim adaptador As New SqlDataAdapter(sql, strCon)
                adaptador.Fill(tabla)


                MsgBox("Password cambiado", MsgBoxStyle.Information, "OK")
            Catch ex As Exception
                MsgBox("Usuario no registrado", MsgBoxStyle.Critical, "Error")
            End Try
        Else
            MsgBox("Password incorrecto", MsgBoxStyle.Information, "Error")
        End If

salto:
    End Sub



    Private Sub textBox2_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles textBox2.KeyPress
        If e.KeyChar = Convert.ToChar(Keys.Return) Then
            Me.button1.PerformClick()
            e.Handled = True
        End If
    End Sub




End Class